<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video controls autoplay :src="url"></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="mvNews.cover" alt />
          </div>
          <span class="name">{{mvNews.artistName}}</span>
        </div>
        <div class="mv-info">
          <h2 class="title">{{mvNews.name}}</h2>
          <span class="date">发布：{{mvNews.publishTime}}</span>
          <span class="number">播放：{{mvNews.playCount}}</span>
          <p class="desc">{{mvNews.desc}}</p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap">
        <p class="title">
          最新评论
          <span class="number">(666)</span>
        </p>
        <div class="comments-wrap">
          <div class="item" v-for="(item , index) in newss" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length != 0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">2020-02-12 17:26:11</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">
          最新评论
          <span class="number">(666)</span>
        </p>
        <div class="comments-wrap">
          <div class="item" v-for="(item , index) in hotnews" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length != 0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">2020-02-12 17:26:11</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="5"
        :limit="limit"
      ></el-pagination>
    </div>
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item" v-for="(item ,index) in mvlist" :key="index">
            <div class="img-wrap">
              <img :src="item.cover" alt />
              <span class="iconfont icon-play" @click="playMv(item.id)"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{item.playCount}}</div>
              </div>
              <span class="time">{{item.duration}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{item.name}}</div>
              <div class="singer">{{item.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "mv",
  data() {
    return {
      // 总条数
      total: 20,
      // 页码
      page: 1,
      // 页容量
      limit: 10,
      url: "",
      mvlist: [],
      mvNews: [],
      hotnews: [],
      newss: []
    };
  },
  created() {
    axios({
      url: "https://autumnfish.cn/mv/url",
      method: "get",
      params: {
        id: this.$route.query.q
      }
    }).then(res => {
      // console.log(res)
      this.url = res.data.data.url;
    });
    this.getmv();
  },
  methods: {
    getmv() {
      axios({
        url: "https://autumnfish.cn/simi/mv",
        method: "get",
        params: {
          mvid: this.$route.query.q
        }
      }).then(res => {
        // console.log(res)
        this.mvlist = res.data.mvs;
        for (let i = 0; i < this.mvlist.length; i++) {
          let duration = this.mvlist[i].duration;
          let min = parseInt(duration / 1000 / 60);
          let sec = parseInt((duration / 1000) % 60);
          if (min < 10) {
            min = "0" + min;
          }
          if (sec < 10) {
            sec = "0" + sec;
          }
          //  console.log(min + ':' + sec)
          this.mvlist[i].duration = min + ":" + sec;
        }
      });
      axios({
        url: "https://autumnfish.cn/mv/detail",
        method: "get",
        params: {
          mvid: this.$route.query.q
        }
      }).then(res => {
        console.log(res);
        this.mvNews = res.data.data;
      });
      axios({
        url: "https://autumnfish.cn/comment/mv",
        method: "get",
        params: {
          id: this.$route.query.q,
          limit: "10",
          offset: "0"
        }
      }).then(res => {
        console.log(res);
        this.hotnews = res.data.comments;
        this.newss = res.data.hotComments;
      });
    },
    playMv(id) {
      axios({
        url: "https://autumnfish.cn/mv/url",
        method: "get",
        params: {
          id: id
        }
      }).then(res => {
        // console.log(res)
        this.url = res.data.data.url;
      });
      this.$route.query.q = id;
      this.getmv();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page = val;
      axios({
        url: "https://autumnfish.cn/comment/mv",
        method: "get",
        params: {
          id: this.$route.query.q,
          limit: this.limit,
          offset: (this.page - 1) * this.limit
        }
      }).then(res => {
        console.log(res);
        this.hotnews = res.data.comments;
        this.newss = res.data.hotComments;
      });
    }
  }
};
</script>

<style></style>
